//
//  CollectViewController.m
//  Youhuiju
//
//  Created by 余尚飞 on 16/8/22.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "CollectViewController.h"
//跳转界面
#import "GoodsDetailViewController.h"

//自定义视图
#import "CollectionTopView.h"

//自定义cell
#import "CollectCollectionViewCell.h"//收藏商品

#import "NoCollectCollectionViewCell.h"//无收藏商品
@interface CollectViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)CollectionTopView *topView;

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;


@end

@implementation CollectViewController

static NSString *CollectCollectionViewCellIden = @"CollectCollectionViewCellIden";
static NSString *NoCollectCollectionViewCellIden = @"NoCollectCollectionViewCellIden";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self load_UI];
    
    NSLog(@"しね");
    
    
    
    // Do any additional setup after loading the view from its nib.
}

#pragma mark ------ load_UI

-(void)load_UI
{
    [self topView];
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"CollectCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:CollectCollectionViewCellIden];
    [self.collectionView registerNib:[UINib nibWithNibName:@"NoCollectCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:NoCollectCollectionViewCellIden];
}

#pragma mark -------- collection delegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
//    return 30;
    return 1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    CollectCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CollectCollectionViewCellIden forIndexPath:indexPath];
//    cell.addCartButtonHandler = ^{
//    
//        DLog(@"加入购物车------收藏界面");
//    };
    
    NoCollectCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NoCollectCollectionViewCellIden forIndexPath:indexPath];
    
    
    return cell;
    
    
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    return CGSizeMake(170 * FitW, 224 * FitH);
    return CGSizeMake(375 * FitW, 603 * FitH);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
//    return UIEdgeInsetsMake(10 * FitH, 12 * FitW, 12 * FitH, 10 * FitW);
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
//    DLog(@"进入商品详情页");
//    GoodsDetailViewController *dvc = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
//    
//    [self.navigationController pushViewController:dvc animated:YES];
    
    DLog(@"去收藏~~~~~~~~~~~~");
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark ----- lazy loading
-(CollectionTopView *)topView
{
    WeakObj(self);
    if (!_topView)
    {
        _topView = [[CollectionTopView alloc]init];
        [self.view addSubview:_topView];
        [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left);
            make.right.equalTo(self.view.mas_right);
            make.top.equalTo(self.view.mas_top).offset(20);
            make.height.mas_offset(44);
        }];
        
        _topView.backButtonClickedHandler = ^{
            
            [weakself.navigationController popViewControllerAnimated:YES];
        };
    }
    return _topView;
}

@end
